#include<iostream>
#include<thread>
#include<mutex>
#include<string>
#include<vector>
#include<future>

void threadA(std::promise<int>& temp, int val) {
    std::cout<<"线程A ID = "<<std::this_thread::get_id()<<std::endl;
    // 一些操作，比如：
    val++;
    val *= 10;
    std::chrono::milliseconds t(5000);
    std::this_thread::sleep_for(t);
    // 保存到temp中
    temp.set_value(val);
    return;
}

void threadB(std::future<int>& temp) {
    auto res = temp.get();
    std::cout<<"线程B ID = "<<std::this_thread::get_id()<<std::endl;
    std::cout<<res<<std::endl;
    return;
}

int main () {
    std::cout<<"main线程ID = "<<std::this_thread::get_id()<<std::endl;
    std::promise<int>myval;
    std::thread thA(threadA, std::ref(myval), 1);
    thA.join();
    auto res = myval.get_future();

    std::thread thB(threadB, std::ref(res));
    thB.join();
    return 1;
}